{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>商品分类</h5>
        </div>
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <div class="col-sm-2">
                        <div class="input-group">
                            <a type="button" class="btn btn-primary btn-outline" href="{:url('product_cate_add')}">添加分类</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="example-wrap">
                <div class="example">
                    <table class="layui-table" lay-filter="brand"
                           lay-data="{height:'full-210',url:'product_cate',method:'post',page:true,id:'brand'}">
                        <thead>
                        <tr>
                            <th lay-data="{title:'ID',field:'product_cate_id',width:60,align:'center',fixed:true,sort:true}"></th>
                            <th lay-data="{title:'名称',field:'product_cate_name',width:200,align:'left'}"></th>
                            <th lay-data="{title:'描述',field:'product_cate_remark',width:200,align:'left'}"></th>
                            <th lay-data="{title:'是否推荐',field:'product_cate_tui',width:100,align:'center',sort:true,templet:'#product_cate_tui'}"></th>
                            <th lay-data="{title:'显示状态',field:'product_cate_status',width:100,align:'center',sort:true,templet:'#product_cate_status'}"></th>
                            <th lay-data="{title:'排序',field:'product_cate_sort',width:80,align:'center',sort:true}"></th>
                            <th lay-data="{title:'创建时间',field:'create_time',width:180,align:'center',sort:true}"></th>
                            <th lay-data="{title:'更新时间',field:'update_time',width:180,align:'center',sort:true}"></th>
                            <th lay-data="{title:'操作',width:100,align:'center',toolbar:'#toolbar',fixed:'right'}"></th>
                        </tr>
                        </thead>
                    </table>
                    <script type="text/html" id="product_cate_status">
                        <input type="checkbox" name="product_cate_status" value="{{d.product_cate_id}}" lay-skin="switch" lay-text="开启|关闭"
                               lay-filter="product_cate_status" {{d.product_cate_status==1?'checked':''}}>
                    </script>
                    <script type="text/html" id="product_cate_tui">
                        <input type="checkbox" name="product_cate_tui" value="{{d.product_cate_id}}" lay-skin="switch" lay-text="是|否"
                               lay-filter="product_cate_tui" {{d.product_cate_tui==1?'checked':''}}>
                    </script>
                    <script type="text/html" id="toolbar">
                        <div class="layui-btn-group">
                            <button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</button>
                            <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript">
    var form = layui.form, table = layui.table;

    /**
     * 监听工具条
     */
    table.on('tool(brand)', function (obj) {
        var data = obj.data; //获得当前行数据
        switch (obj.event) {
            case 'edit':
                location.href = "product_cate_edit/product_cate_id/" + data.product_cate_id;
                // console.log(data)
                break;
            case 'del':
                // 删除记录
                layer.confirm('您确定要删除该记录吗？', {
                    title: false,
                    btn: ['确定', '取消'],
                    closeBtn: false,
                    btnAlign: 'c',
                    yes: function (index) {
                        $.post("{:url('product_cate_del')}", {product_cate_id: data.product_cate_id}, function (response) {
                            layer.msg(response.msg);
                            if (response.code === 200) {
                                obj.del();
                            }
                        });
                        layer.close(index);
                    }
                });
                break;
        }
    });

    /**
     * 监听是否显示
     */
    form.on('switch(product_cate_status)', function (obj) {
        $.post("{:url('product_cate_status')}", {product_cate_id: this.value}, function (result) {
        });
    });
    /**
     * 监听是否推荐
     */
    form.on('switch(product_cate_tui)', function (obj) {
        $.post("{:url('product_cate_tui')}", {product_cate_id: this.value}, function (result) {
        });
    });
</script>
</body>
</html>